feat(effect): Export layers for browser | setTracer in buildEffectTracer#19816
feat(effect): Export layers for browser | setTracer in buildEffectTracer#19816JPeer264 merged 2 commits intojp/add-effect-sdkfrom
Conversation
| * Effect Layer that sets up the Sentry tracer for Effect spans. | ||
| */ | ||
| export const SentryEffectTracerLayer: Layer.Layer<never, never, never> = setTracer(makeSentryTracer()); | ||
| export const SentryEffectTracer = makeSentryTracer(); |
There was a problem hiding this comment.
Bug: The export SentryEffectTracerLayer was renamed, but the test file tracer.test.ts was not updated and still imports the old, non-existent name, which will break tests.
Severity: HIGH
Suggested Fix
Update packages/effect/test/tracer.test.ts to import the new SentryEffectTracer and wrap it with setTracer before providing it to the Effect in the tests, for example: Effect.provide(setTracer(SentryEffectTracer)). Also, remove the unused setTracer import from packages/effect/src/tracer.ts.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: packages/effect/src/tracer.ts#L201
Potential issue: The refactoring in `packages/effect/src/tracer.ts` replaced the `Layer`
export `SentryEffectTracerLayer` with a raw `Tracer` object named `SentryEffectTracer`.
However, the corresponding test file, `packages/effect/test/tracer.test.ts`, was not
updated. It continues to import `SentryEffectTracerLayer`, which no longer exists. This
import will resolve to `undefined` at runtime, causing all 16 test cases that call
`Effect.provide(SentryEffectTracerLayer)` to fail with a runtime error. Additionally, an
unused import for `setTracer` remains in `tracer.ts`.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Autofix Details
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Conditional tracing breaks existing test expecting Sentry tracer
- Updated the test to pass tracesSampleRate: 1.0 to createClient() so hasSpansEnabled returns true and the Sentry tracer is properly added.
- ✅ Fixed: No new tests for conditional tracing behavior
- Added two new tests to verify conditional tracing behavior: one for when spans are disabled (no tracesSampleRate) and one for when tracesSampler is set.
Or push these changes by commenting:
@cursor push a9719126b9
Preview (a9719126b9)
diff --git a/packages/effect/src/index.client.ts b/packages/effect/src/index.client.ts
--- a/packages/effect/src/index.client.ts
+++ b/packages/effect/src/index.client.ts
@@ -6,6 +6,6 @@
export { effectLayer, init } from './client/index';
export type { EffectClientLayerOptions } from './client/index';
-export { SentryEffectTracer } from './tracer';
+export { SentryEffectTracer, SentryEffectTracerLayer } from './tracer';
export { SentryEffectLogger } from './logger';
export { SentryEffectMetricsLayer } from './metrics';
diff --git a/packages/effect/src/index.server.ts b/packages/effect/src/index.server.ts
--- a/packages/effect/src/index.server.ts
+++ b/packages/effect/src/index.server.ts
@@ -3,6 +3,6 @@
export { effectLayer, init } from './server/index';
export type { EffectServerLayerOptions } from './server/index';
-export { SentryEffectTracer } from './tracer';
+export { SentryEffectTracer, SentryEffectTracerLayer } from './tracer';
export { SentryEffectLogger } from './logger';
export { SentryEffectMetricsLayer } from './metrics';
diff --git a/packages/effect/src/tracer.ts b/packages/effect/src/tracer.ts
--- a/packages/effect/src/tracer.ts
+++ b/packages/effect/src/tracer.ts
@@ -199,3 +199,8 @@
* Effect Layer that sets up the Sentry tracer for Effect spans.
*/
export const SentryEffectTracer = makeSentryTracer();
+
+/**
+ * Effect Layer that sets up the Sentry tracer for Effect spans.
+ */
+export const SentryEffectTracerLayer: Layer.Layer<never, never, never> = setTracer(SentryEffectTracer);
diff --git a/packages/effect/test/buildEffectLayer.test.ts b/packages/effect/test/buildEffectLayer.test.ts
--- a/packages/effect/test/buildEffectLayer.test.ts
+++ b/packages/effect/test/buildEffectLayer.test.ts
@@ -136,8 +136,32 @@
}),
);
startInactiveSpanSpy.mockRestore();
+ }).pipe(Effect.provide(buildEffectLayer({}, createClient({ tracesSampleRate: 1.0 })))),
+ );
+
+ it.effect('layer does not enable tracing when tracesSampleRate is not set', () =>
+ Effect.gen(function* () {
+ const startInactiveSpanSpy = vi.spyOn(sentryCore, 'startInactiveSpan');
+ const result = yield* Effect.withSpan('test-span-no-tracing')(Effect.succeed('not-traced'));
+ expect(result).toBe('not-traced');
+ expect(startInactiveSpanSpy).not.toHaveBeenCalled();
+ startInactiveSpanSpy.mockRestore();
}).pipe(Effect.provide(buildEffectLayer({}, createClient()))),
);
+
+ it.effect('layer enables tracing when tracesSampler is set', () =>
+ Effect.gen(function* () {
+ const startInactiveSpanSpy = vi.spyOn(sentryCore, 'startInactiveSpan');
+ const result = yield* Effect.withSpan('test-sampler-span')(Effect.succeed('sampled'));
+ expect(result).toBe('sampled');
+ expect(startInactiveSpanSpy).toHaveBeenCalledWith(
+ expect.objectContaining({
+ name: 'test-sampler-span',
+ }),
+ );
+ startInactiveSpanSpy.mockRestore();
+ }).pipe(Effect.provide(buildEffectLayer({}, createClient({ tracesSampler: () => true })))),
+ );
});
describe('with additional options', () => {This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
size-limit report 📦
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
There was a problem hiding this comment.
ignoring this for the review since we remove it in #19823
…cer (#19816) This changes three things in one go: - Export `SentryEffectTracer`, `SentryEffectLogger` and `SentryEffectMetricsLayer` for bundle sizes in the browser (and node if they want to go that route) - Respect `tracesSampleRate` when using `Sentry.effectLayer`, so tracing is only added when needed - Moving `setTracer` outside of `SentryEffectTracerLayer` to make it Effect native, where users could call `setTracer` on their own if they want to


This changes three things in one go:
SentryEffectTracer,SentryEffectLoggerandSentryEffectMetricsLayerfor bundle sizes in the browser (and node if they want to go that route)tracesSampleRatewhen usingSentry.effectLayer, so tracing is only added when neededsetTraceroutside ofSentryEffectTracerLayerto make it Effect native, where users could callsetTraceron their own if they want to